using B.S.RbacData.ErrorCode;
using ContentmanagementBaseRead.API.Applications.Commands;
using ContentmanagementBaseRead.API.Dtos;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace ContentmanagementBaseRead.API.Controllers
{
    /// <summary>
    /// 内容管理控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class CarouselController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<CarouselController> _logger;

        public CarouselController(IMediator mediator, ILogger<CarouselController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }

        /// <summary>
        /// 获取轮播图列表
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet("list")]
        public async Task<ApiPaging<List<CarouelChartDtos>>> GetCarouselList([FromQuery] GetCarouselCommand command)
        {
            try
            {
                var result = await _mediator.Send(command);

                return result;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取轮播图列表过程中发生异常，页码：{PageIndex}，每页数量：{PageSize}",
                    command.PageIndex, command.PageSize);

                return new ApiPaging<List<CarouelChartDtos>>
                {
                    code = ResultEnumCode.fails,
                    message = $"获取轮播图列表异常：{ex.Message}",
                    data = new List<CarouelChartDtos>(),
                    TotalCount = 0,
                    PageCount = 0,
                };
            }
        }

       
    }
}